package org.to_zero.ssm.sdm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.to_zero.ssm.sdm.entity.vo.ResponseEntity;
import org.to_zero.ssm.sdm.service.FileTransferService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class FileTransferController {

    @Autowired
    private FileTransferService fileTransferService;

    @PostMapping("/admin/upload")
    public ResponseEntity upload(MultipartFile[] file, HttpServletRequest request) {
        return fileTransferService.upload(file);
    }

    @GetMapping("/admin/download/{fileName}")
    public ResponseEntity upload(@PathVariable String fileName, HttpSession session) {
        return fileTransferService.download(fileName, session);
    }
}
